package com.virtual.repository.common.model.adapters;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import com.virtual.repository.common.model.Mapping;

/**
 * Class defines methods for adapting a an array of <code>Mapping</code> elements, represented by <code>Mappings</code> class
 * to a map of <code>mapping</code> elements, represented by <code>Map<String, Mapping></code>. 
 * The methods are invoked by the JAXB binding framework during marshaling and unmarshalling.
 * 
 * @author kchaber
 *
 */
public class MappingMapAdapter extends XmlAdapter<Mappings , Map<String, Mapping>>{

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Map<String, Mapping> unmarshal(Mappings mappings) throws Exception {
		Map<String, Mapping> result = new HashMap<>();
		for (Mapping m : mappings.values) {
			result.put(m.getClassName(), m);
		}
		return result;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Mappings marshal(Map<String, Mapping> v) throws Exception {
		throw new UnsupportedOperationException("This method has not be implemented yet");
	}


}
